/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sg.edu.nus.iss.pacman.service.impl;

import sg.edu.nus.iss.pacman.constant.Constants;
import sg.edu.nus.iss.pacman.util.PacManUtil;
import sg.edu.nus.iss.pacman.dao.PacManDAO;
import sg.edu.nus.iss.pacman.dao.impl.PacManDAOImpl;
import sg.edu.nus.iss.pacman.exception.MapException;
import sg.edu.nus.iss.pacman.service.MapService;

/**
 *
 * @author Tabiul Mahmood
 */
public class MapServiceImpl implements MapService
{
    public byte[] getMap(String mapName) throws MapException
    {
        try
        {
            String filename = Constants.MAP_FOLDER + mapName + ".xml";
            String mapFile = PacManUtil.getFileFromResourceStream(filename);
            return mapFile.getBytes();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            throw new MapException(mapName);
        }
    }

    public String[] getMapListing()
    {
        PacManDAO pacManDAO = new PacManDAOImpl();
        return PacManUtil.convertToArray(pacManDAO.getMapListing());
    }
}
